package com.gitee.feizns.quickstart.ding.talk.api.top.api.role;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRoleAddrolegroupRequest;
import com.dingtalk.api.response.OapiRoleAddrolegroupResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 创建角色组（/role/add_role_group）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/add-a-role-group">创建角色组（/role/add_role_group）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/add-a-role-group">服务端API > 通讯录管理 > 角色管理 > 创建角色组</a>
 * @author feizns
 * @since 2024/7/28
 */
public class AddRoleGroup {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param name 名字
     * @return {@link Long }
     */
    @SneakyThrows
    public static Long execute(String accessToken, String name) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role_group");
        OapiRoleAddrolegroupRequest req = new OapiRoleAddrolegroupRequest();
        req.setName(name);
        OapiRoleAddrolegroupResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getGroupId();
    }

}
